<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商家登录 - 校园点餐系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body { background: linear-gradient(135deg, #43cea2 0%, #185a9d 100%); min-height: 100vh; display: flex; align-items: center; }
    </style>
</head>
<body>
    <div class="container">
        <div class="card shadow-lg mx-auto" style="max-width: 400px;">
            <div class="card-body p-5">
                <div class="text-center mb-4">
                    <h3>商家登录</h3>
                    <p class="text-muted">管理您的店铺</p>
                </div>
                <form id="loginForm">
                    <div class="mb-3">
                        <label class="form-label">联系电话</label>
                        <input type="text" class="form-control" name="username" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">密码</label>
                        <input type="password" class="form-control" name="password" required>
                    </div>
                    <button type="submit" class="btn btn-success w-100">登录</button>
                    <div class="text-center mt-3">
                        <a href="/index" class="text-muted">返回首页</a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
    <script>
        $('#loginForm').submit(function(e) {
            e.preventDefault();
            $.ajax({
                url: '/api/auth/merchant/login',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({
                    username: $('input[name="username"]').val(),
                    password: $('input[name="password"]').val()
                }),
                success: function(res) {
                    if (res.code === 200) {
                        localStorage.setItem('token', res.data.token);
                        alert('登录成功！');
                        window.location.href = '/merchant/manage';
                    } else {
                        alert(res.message);
                    }
                },
                error: function(xhr) {
                    alert(xhr.responseJSON?.message || '登录失败');
                }
            });
        });
    </script>
</body>
</html>

